package com.xuetang9.fujian.threaddemo;

import java.util.concurrent.TimeUnit;

/**
 * @author: fujian
 * @description: 打印任务
 * @date: 2021/5/2 10:59
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo
 **/
public class PrintTask implements Runnable{
    private String printInfo = "";
    private int printCount = 0;
    private String threadName;

    public PrintTask() {
    }

    public PrintTask(String printInfo, int printCount, String threadName) {
        this.printInfo = printInfo;
        this.printCount = printCount;
        this.threadName = threadName;
    }

    @Override
    public void run() {
        System.out.println("线程：" + this.threadName + "开启");
        printCount += 1;
        while (--printCount >= 0){
            System.out.println("第" + printCount + "次打印：" + printInfo);
            try {
                TimeUnit.MILLISECONDS.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("-----------------线程" + this.threadName + "打印完毕-----------------");
    }

    public static void main(String[] args) {
        PrintTask printTask1 = new PrintTask("大吉大利,今晚吃鸡",100,"任务一");
        PrintTask printTask2 = new PrintTask("Lok' Tar Ogar",100,"任务二");
        Thread thread1 = new Thread(printTask1);
        Thread thread2 = new Thread(printTask2);
        thread1.start();
        thread2.start();

    }
}
